﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WuDada.Core.Member.Domain;
using WuDada.Core.Member.Persistence;

namespace WuDada.Core.Member.Service.Impl
{
    public class MemberService : IMemberService
    {
        public IMemberDao MemberDao { get; set; }

        /// <summary>
        /// 新增Member
        /// </summary>
        /// <param name="memberVO">被新增的Member</param>
        /// <returns>新增後的Member</returns>
        public MemberVO CreateMember(MemberVO memberVO)
        {
            return MemberDao.CreateMember(memberVO);
        }

        /// <summary>
        /// 取得Member By MemberId
        /// </summary>
        /// <param name="memberId">MemberId</param>
        /// <returns>Member</returns>
        public MemberVO GetMemberById(int memberId)
        {
            return MemberDao.GetMemberById(memberId);
        }

        /// <summary>
        /// 取得Member By LoginId
        /// </summary>
        /// <param name="loginId">LoginId</param>        
        /// <returns>Member</returns>
        public MemberVO GetMemberByLoginId(string loginId)
        {
            return MemberDao.GetMemberByLoginId(loginId);
        }

        /// <summary>
        /// 刪除Member
        /// </summary>
        /// <param name="memberVO">被刪除的Member</param>
        public void DeleteMember(MemberVO memberVO)
        {
            MemberDao.DeleteMember(memberVO);
        }

        /// <summary>
        /// 更新Member
        /// </summary>
        /// <param name="memberVO">被更新的Member</param>
        /// <returns>更新後的Member</returns>
        public MemberVO UpdateMember(MemberVO memberVO)
        {
            return MemberDao.UpdateMember(memberVO);
        }

        /// <summary>
        /// 取得Member
        /// </summary>
        /// <param name="sortField">排序欄位</param>
        /// <param name="sortDesc">升降冪排序</param>
        /// <returns>Member清單</returns>
        public IList<MemberVO> GetMemberList(string sortField, bool sortDesc)
        {
            return MemberDao.GetMemberList(sortField, sortDesc);
        }

        /// <summary>
        /// 取得Member
        /// </summary>
        /// <param name="pageIndex">分頁索引</param>
        /// <param name="pageSize">分頁大小</param>
        /// <param name="sortField">排序欄位</param>
        /// <param name="sortDesc">升降冪排序</param>
        /// <returns>Member清單</returns>
        public IList<MemberVO> GetMemberList(int pageIndex, int pageSize, string sortField, bool sortDesc)
        {
            return MemberDao.GetMemberList(pageIndex, pageSize, sortField, sortDesc);
        }

        /// <summary>
        /// 取得Member筆數
        /// </summary>
        /// <returns>Member清單</returns>
        public int CountMemberList()
        {
            return MemberDao.CountMemberListByPostId();
        }

        /// <summary>
        /// 動態查詢筆數Member
        /// </summary>
        /// <param name="where">搜尋語法，用Where...order by ...</param>
        /// <returns>筆數</returns>
        public int CountMemberByWhere(string where)
        {
            return MemberDao.CountMemberByWhere(where);
        }

        /// <summary>
        /// 動態查詢Member
        /// </summary>
        /// <param name="where">搜尋語法，用Where...order by ...</param>
        /// <param name="pageIndex">分頁索引</param>
        /// <param name="pageSize">分頁大小</param>
        /// <returns>搜尋結果</returns>
        public IList<MemberVO> SearchMemberByWhere(string where, int pageIndex, int pageSize)
        {
            return MemberDao.SearchMemberByWhere(where, pageIndex, pageSize);
        }
    }
}
